package com.xinfu.newproject.ui.pay_cost;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.xinfu.newproject.R;
import com.xinfu.newproject.adapter.paycost_adapter.PayCostTypeAdapter;
import com.xinfu.newproject.base.BaseActivity;
import com.xinfu.newproject.bean.certifition.ResidentBean;
import com.xinfu.newproject.bean.certifition.ResidentCertificationBean;
import com.xinfu.newproject.bean.paycost.bean.GetBillByTypeBean;
import com.xinfu.newproject.bean.paycost.bean.QueryTypesBean;
import com.xinfu.newproject.presenter.PayCostPresenter;
import com.xinfu.newproject.util.BToast;
import com.xinfu.newproject.view.IView;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.disposables.Disposable;

public class PayCostTypeActivity extends BaseActivity implements IView.IPayCostView {

    @BindView(R.id.activity_pay_cost_type_rv)
    RecyclerView mRecyclerView;

    PayCostTypeAdapter payCostTypeAdapter;

    private PayCostPresenter payCostPresenter = new PayCostPresenter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_cost_type);
        ButterKnife.bind(this);
        registerBack();
        initViewBind();
        initLisener();
    }

    private void initLisener() {

    }

    private void initViewBind() {
        setActivityTitle("缴费类型");
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        payCostTypeAdapter = new PayCostTypeAdapter();
        mRecyclerView.setAdapter(payCostTypeAdapter);
        payCostTypeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        Bundle bundle = new Bundle();
                        bundle.putString("response", getIntent().getExtras().getString("response"));
                        bundle.putString("type", queryTypesBean.getResult().get(position).getType());
                        startIntentActivity(PropertyFeeActivity.class, bundle);
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                }
            }
        });
    }

    int tenantId;

    @Override
    protected void onResume() {
        super.onResume();
        if (getIntent().getExtras() != null) {
            String response = getIntent().getExtras().getString("response");
            ResidentBean residentBeans = new Gson().fromJson(response, ResidentBean.class);
            ResidentCertificationBean.ResultBean.RoomCheckUserListBean video = (ResidentCertificationBean.ResultBean.RoomCheckUserListBean) residentBeans.t;
            tenantId = video.getTenantId();
            payCostPresenter.queryTypes();
        }
    }

    @Override
    public String header() {
        return String.valueOf(tenantId);
    }

    @Override
    public String type() {
        return null;
    }

    @Override
    public String roomId() {
        return null;
    }

    @Override
    public String cusOrRent() {
        return null;
    }

    @Override
    public void showToast(String content) {
        BToast.showText(this, content);
    }

    @Override
    public void closeDispose(Disposable disposable) {

    }

    @Override
    public void showProgress() {
//        showLoding("");
    }

    @Override
    public void hideProgress() {
//        hideLoding();
    }

    QueryTypesBean queryTypesBean;

    @Override
    public void getData(QueryTypesBean queryTypesBean) {
        if (queryTypesBean.getResult() != null) {
            this.queryTypesBean = queryTypesBean;
            payCostTypeAdapter.setNewData(queryTypesBean.getResult());
        }
    }

    @Override
    public void getData(GetBillByTypeBean getBillByTypeBean) {

    }
}
